﻿using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using Lamex.Base;
using Lamex.Interface;
using Lamex.Library;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Lamex.Common;
using System.Resources;
using System.Reflection;
using Lamex.Library.CommonClass;
using DevExpress.XtraGrid;
using Lamex.Controls;
using DevExpress.XtraGrid.Columns;
using Lamex.Library.UI;
using DevExpress.Utils;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;
using System.IO;
using DevExpress.ClipboardSource.SpreadsheetML;

namespace Lamex.Library
{
    public partial class frmBaseChildWinForm : frmBaseChild
    {
        string dataBaseName = "";
        DataTable dtImport = null;
        ResourceManager rm = null;
        DataTable dt = null;
        string isEdit = "";
        string dtName = "";
        int Captain_xTop = 0;
        int Captain_xLeft = 0;
        int tabIndex_xTop = 0;
        int tabIndex_xLeft = 0;
        int iYAddDis = 0;
        int iCurrentRow = 0;//当前行
        int IsFormEdit = 1;

        DevExpress.XtraEditors.LabelControl lbfont = new DevExpress.XtraEditors.LabelControl();
        List<int> Captain_xTop_List = new List<int>();
        List<int> Captain_xLeft_List = new List<int>();
        private DevExpress.XtraGrid.GridControl gcView1 = new GridControl();
        private DevExpress.XtraGrid.Views.Grid.GridView gcViewMain = new GridView();
        string gcCNBoxAll = "新增/编辑";
        string gcENBoxAll = "Add/Edit";
        string gcCNEdit = "编辑";
        string gcENEdit = "Edit";
        string gcCNAdd = "新增";
        string gcENAdd = "Add";
        string IsEidtWhere = "";
        string QUERY_SHOW_FLAG = "false";
        int iType = 0;
        bool IsEdit = false;
        bool IsRefresh = false;
        DataTable dtDatasource = null;


        public frmBaseChildWinForm(string dtName, int iType, bool isEdit, bool isRefresh)
        {
            InitializeComponent();
            this.IsEdit = isEdit;
            this.IsRefresh = isRefresh;
            this.dtName = dtName;
            this.Load += new EventHandler(frmBaseChildWinForm_Load);
            gcView1.DoubleClick += new EventHandler(gcView1_DoubleClick);
            gcView1.Click += new EventHandler(gcView1_Click);
            gcView1.KeyDown += new KeyEventHandler(gcView1_KeyDown);
            this.TextChanged += new EventHandler(frmBaseChildWinForm_TextChanged);
            gcViewMain.RowStyle += new RowStyleEventHandler(gcViewMain_RowStyle);
            this.iType = iType;
        }
        public frmBaseChildWinForm()
        {

        }
        public void frmBaseChildWinForm_Load(object sender, EventArgs e)
        {
            try { this.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理
            init();
            RetureControlStr.IsEnableControl(plEditPanel, true);
            if (IsRefresh == true)
                DoView(null);

        }

        private void init()
        {
            this.plLeft.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
            this.plLeftView.Controls.Add(this.gcView1);
            this.gcView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.gcView1.Location = new System.Drawing.Point(0, 43);
            this.gcView1.MainView = this.gcViewMain;
            this.gcView1.Name = "gcView1";

            this.gcView1.Size = new System.Drawing.Size(686, 407);
            this.gcView1.TabIndex = 0;
            this.gcView1.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] {
            this.gcViewMain});
            this.gcViewMain.GroupSummary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
            new DevExpress.XtraGrid.GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count, "", null, "")});
            this.gcViewMain.OptionsView.ShowFooter = true;

            dt = Lamex.Base.BaseBuildSql.GetDataTableBySql("select * from Sys_FormControl where FORM_TABLE_NAME='" + dtName + "' order by CTRL_SEQUENCE  ");
            dtDatasource = dt;
            if (dt != null)
            {
                DataRow dr = dt.Select("1=1").FirstOrDefault();

                if (Lamex.Common.Loginer.CurrentUser.ChangeLanguage == 0)
                    this.Text = dr["FORM_CN_NAME"].ToString().Trim();
                else
                    this.Text = dr["FORM_EN_NAME"].ToString().Trim();
                dataBaseName = dr["DATABASE_NAME"].ToString().Trim();
                if (IsEdit == true)
                    IsFormEdit = 1;
                else
                    IsFormEdit = 0;
            }
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["FILTER_FLAG"].ToString().ToLower() == "true")
                {
                    if (Lamex.Common.Loginer.CurrentUser.ChangeLanguage == 0)
                    {
                        var str = dr["CTRL_CN_NAME"].ToString().Trim() + "： " + "(≥)";

                        SizeF size = lbfont.CreateGraphics().MeasureString(str, lbfont.Font);
                        lbfont.Width = (int)size.Width;
                        Captain_xLeft_List.Add((int)size.Width);
                        Captain_xTop_List.Add((int)size.Width);

                    }
                    else
                    {
                        var str = dr["CTRL_EN_NAME"].ToString().Trim() + "： " + "(≥)";

                        SizeF size = lbfont.CreateGraphics().MeasureString(str, lbfont.Font);
                        lbfont.Width = (int)size.Width;
                        Captain_xLeft_List.Add((int)size.Width);
                        Captain_xTop_List.Add((int)size.Width);
                    }
                }
                else
                {
                    if (Lamex.Common.Loginer.CurrentUser.ChangeLanguage == 0)
                    {
                        var str = dr["CTRL_CN_NAME"].ToString().Trim() + "： " + "(≥)";
                        SizeF size = lbfont.CreateGraphics().MeasureString(str, lbfont.Font);
                        lbfont.Width = (int)size.Width;
                        Captain_xLeft_List.Add((int)size.Width);

                    }
                    else
                    {
                        var str = dr["CTRL_EN_NAME"].ToString().Trim() + "： " + "(≥)";
                        SizeF size = lbfont.CreateGraphics().MeasureString(str, lbfont.Font);
                        lbfont.Width = (int)size.Width;
                        Captain_xLeft_List.Add((int)size.Width);
                    }

                }

            }
            Rectangle ScreenArea = System.Windows.Forms.Screen.GetWorkingArea(this);
            int iWinWidth = ScreenArea.Width;
            //plRight.Width = iWinWidth / 4;
            //plLeft.Width = 3* iWinWidth / 4;
            gcmIWCEBox.Dock = DockStyle.Fill;
            Captain_xLeft = Captain_xLeft_List.Max();
            Captain_xTop = Captain_xTop_List.Max();
            //control topPanel four condition ration///
            int xtopAddPanelCount = Captain_xTop_List.Count / 4;
            int xtopAddPanelMod = Captain_xTop_List.Count % 4;
            int xtopLeft = 2, ytopleft = 4, disX = 2, disY = 2;
            int xLeft = 1, yLeft = 22, disLeft = 5;
            int iChangeRow = 0;


            //计算toppanel和控件之前的宽度
            int iplWith = 0, iplDis = 0, iTextRealUse = 0, ixLeftTextRealUse = 100;
            plTop.Height = 26;
            iplWith = plTop.Width - disX * 4 - Captain_xTop * 4;
            //作居中用
            int xleftCenter = (plEditPanel.Width - Captain_xLeft - ixLeftTextRealUse) / 2;

            //计算rightPanal上面的宽度占比
            iTextRealUse = iplWith / 4;
            if (iTextRealUse > 120) iTextRealUse = 120;
            xleftCenter = -1;
            plRight.Width = 40 + Captain_xLeft + ixLeftTextRealUse;



            foreach (DataRow dr in dt.Rows)
            {
                string FiledName = "";
                string alterMessage = "";
                if (Lamex.Common.Loginer.CurrentUser.ChangeLanguage == 0)
                {
                    FiledName = dr["CTRL_CN_NAME"].ToString();
                    alterMessage = FiledName + "不能为空！";
                    if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                    {
                        this.gcViewMain.Columns.AddVisible(dr["WRITE_FIELD_NAME"].ToString().Trim(), dr["CTRL_CN_NAME"].ToString());
                        if (dr["CTRL_VALUE_TYPE"].ToString().Trim().ToLower().Contains("decimal") || dr["CTRL_VALUE_TYPE"].ToString().Trim().ToLower().Contains("int"))
                        {
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.DisplayFormat = "{0:0.##}";
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.FieldName = "";
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;//求和
                        }

                        if (dr["CTRL_VALUE_TYPE"].ToString().ToLower().Trim() == "datetime")
                        {
                            DevExpress.XtraEditors.Repository.RepositoryItemDateEdit uc = new RepositoryItemDateEdit();
                            uc.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            uc.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                            uc.EditFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            uc.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                            this.gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString()].ColumnEdit = uc;
                        }
                        else if (dr["CTRL_VALUE_TYPE"].ToString().ToLower().Trim() == "pictrueedit")
                        {
                            DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit uc = new RepositoryItemPictureEdit();
                            uc.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
                            this.gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString()].UnboundType = DevExpress.Data.UnboundColumnType.Object;
                            this.gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString()].ColumnEdit = uc;

                        }



                    }
                    else
                    {
                        this.gcViewMain.Columns.AddVisible(dr["REF_FIELD_VALUE"].ToString().Trim(), dr["CTRL_CN_NAME"].ToString());
                        if (dr["CTRL_VALUE_TYPE"].ToString().Trim().ToLower().Contains("decimal") || dr["CTRL_VALUE_TYPE"].ToString().Trim().ToLower().Contains("int"))
                        {
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.DisplayFormat = "{0:0.##}";
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.FieldName = "";
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;//求和
                        }
                        if (dr["CTRL_VALUE_TYPE"].ToString().ToLower().Trim() == "datetime")
                        {
                            DevExpress.XtraEditors.Repository.RepositoryItemDateEdit uc = new RepositoryItemDateEdit();
                            uc.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            uc.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                            uc.EditFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            uc.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                            this.gcViewMain.Columns[dr["REF_FIELD_NAME"].ToString()].ColumnEdit = uc;
                        }
                        else if (dr["CTRL_VALUE_TYPE"].ToString().ToLower().Trim() == "pictrueedit")
                        {
                            DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit uc = new RepositoryItemPictureEdit();
                            uc.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
                            this.gcViewMain.Columns[dr["REF_FIELD_NAME"].ToString()].UnboundType = DevExpress.Data.UnboundColumnType.Object;
                            this.gcViewMain.Columns[dr["REF_FIELD_NAME"].ToString()].ColumnEdit = uc;

                        }

                    }

                }
                else
                {
                    FiledName = dr["CTRL_EN_NAME"].ToString();
                    alterMessage = FiledName + " cann't empty！";
                    if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                    {
                        this.gcViewMain.Columns.AddVisible(dr["WRITE_FIELD_NAME"].ToString().Trim(), dr["CTRL_EN_NAME"].ToString());
                        if (dr["CTRL_VALUE_TYPE"].ToString().Trim().ToLower().Contains("decimal") || dr["CTRL_VALUE_TYPE"].ToString().Trim().ToLower().Contains("int"))
                        {
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.DisplayFormat = "{0:0.##}";
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.FieldName = "";
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;//求和
                        }
                        if (dr["CTRL_VALUE_TYPE"].ToString().ToLower().Trim() == "datetime")
                        {
                            DevExpress.XtraEditors.Repository.RepositoryItemDateEdit uc = new RepositoryItemDateEdit();
                            uc.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            uc.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                            uc.EditFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            uc.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                            this.gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString()].ColumnEdit = uc;
                        }
                        else if (dr["CTRL_VALUE_TYPE"].ToString().ToLower().Trim() == "pictrueedit")
                        {
                            DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit uc = new RepositoryItemPictureEdit();
                            uc.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
                            this.gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString()].UnboundType = DevExpress.Data.UnboundColumnType.Object;
                            this.gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString()].ColumnEdit = uc;

                        }




                    }
                    else
                    {
                        this.gcViewMain.Columns.AddVisible(dr["REF_FIELD_VALUE"].ToString().Trim(), dr["CTRL_EN_NAME"].ToString());
                        if (dr["CTRL_VALUE_TYPE"].ToString().Trim().ToLower().Contains("decimal") || dr["CTRL_VALUE_TYPE"].ToString().Trim().ToLower().Contains("int"))
                        {
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.DisplayFormat = dr["CTRL_EN_NAME"].ToString() + ":{0:0.##}";
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.FieldName = "";
                            gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString().Trim()].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;//求和
                        }
                        if (dr["CTRL_VALUE_TYPE"].ToString().ToLower().Trim() == "datetime")
                        {
                            DevExpress.XtraEditors.Repository.RepositoryItemDateEdit uc = new RepositoryItemDateEdit();
                            uc.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            uc.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                            uc.EditFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            uc.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                            this.gcViewMain.Columns[dr["REF_FIELD_VALUE"].ToString()].ColumnEdit = uc;
                        }
                        else if (dr["CTRL_VALUE_TYPE"].ToString().ToLower().Trim() == "pictrueedit")
                        {
                            DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit uc = new RepositoryItemPictureEdit();
                            uc.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
                            this.gcViewMain.Columns[dr["REF_FIELD_VALUE"].ToString()].UnboundType = DevExpress.Data.UnboundColumnType.Object;
                            this.gcViewMain.Columns[dr["REF_FIELD_VALUE"].ToString()].ColumnEdit = uc;

                        }

                    }

                }
                //if (dr["VISIBLE_FLAG"].ToString().ToLower() == "false")
                //    this.gcViewMain.Columns[dr["WRITE_FIELD_NAME"].ToString()].Visible = false;

                //控件布局
                int y = 0;
                if (dr["FILTER_FLAG"].ToString().ToLower() == "true")
                {
                    if (dr["CTRL_TYPE"].ToString().ToLower() == "textedit")
                    {

                        Lamex.Controls.ucTextEdit ucEdit = new Controls.ucTextEdit();
                        ucEdit.Caption = FiledName + "： ";
                        ucEdit.CaptionVisible = true;
                        ucEdit.CaptionWidth = Captain_xTop;
                        ucEdit.Location = new Point(xtopLeft, ytopleft);
                        ucEdit.Size = new Size(Captain_xTop + iTextRealUse, 17);

                        ucEdit.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                            ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                        else
                            ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();
                        ucEdit.TabIndex = tabIndex_xTop;
                        xtopLeft += ucEdit.Width + disX;//横向布局控件


                        plTop.Controls.Add(ucEdit);
                        y = ucEdit.Height;
                        tabIndex_xTop++;

                        iChangeRow++;
                        if (iChangeRow % 4 == 0)
                        {
                            iYAddDis++;
                            if (iYAddDis <= xtopAddPanelCount)
                            {
                                if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                {
                                    ytopleft += y + disY * 2;//横向布局控件
                                    xtopLeft = 2;//横向布局控件
                                    plTop.Height = ytopleft + y + disY * 4;
                                }
                                else
                                {
                                    if (xtopAddPanelMod != 0)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                }

                            }

                        }

                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "combobox")
                    {


                        Lamex.Controls.ucComboBoxEdit ucEdit = new Controls.ucComboBoxEdit();
                        ucEdit.Properties.Items.Clear();
                        ucEdit.Caption = FiledName + "： ";
                        ucEdit.CaptionVisible = true;
                        ucEdit.CaptionWidth = Captain_xTop;
                        ucEdit.Location = new Point(xtopLeft, ytopleft);
                        ucEdit.Size = new Size(Captain_xTop + iTextRealUse, 17);
                        ucEdit.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                            ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                        else
                            ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();

                        ucEdit.TabIndex = tabIndex_xTop;
                        xtopLeft += ucEdit.Width + disX;//横向布局控件

                        plTop.Controls.Add(ucEdit);
                        y = ucEdit.Height;
                        tabIndex_xTop++;




                        DataTable dtList = BaseBuildSql.GetDataTableBySql(" select * from Sys_ControlValueOption where FIELD_NAME='" + dr["CTRL_EN_NAME"].ToString() + "'");
                        foreach (DataRow d in dtList.Rows)
                        {
                            string[] sPlitList = d["FIELD_VALUE_OPTION"].ToString().Split(',');
                            foreach (string s in sPlitList)
                                ucEdit.Properties.Items.Add(s);
                        }

                        iChangeRow++;
                        if (iChangeRow % 4 == 0)
                        {
                            iYAddDis++;

                            if (iYAddDis <= xtopAddPanelCount)
                            {
                                if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                {
                                    ytopleft += y + disY * 2;//横向布局控件
                                    xtopLeft = 2;//横向布局控件
                                    plTop.Height = ytopleft + y + disY * 4;
                                }
                                else
                                {
                                    if (xtopAddPanelMod != 0)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                }

                            }



                        }
                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "lookupedit")
                    {
                        DataTable dtList = BaseBuildSql.GetDataTableBySql(" select " + dr["REF_FIELD_NAME"].ToString() + "," + dr["REF_FIELD_VALUE"].ToString() + " from " + dr["REF_TABLE"].ToString() + "");
                        Lamex.Controls.ucLookUpEdit ucEdit = new Controls.ucLookUpEdit();
                        ucEdit.Caption = FiledName + "： ";
                        ucEdit.CaptionVisible = true;
                        ucEdit.CaptionWidth = Captain_xTop;
                        ucEdit.Location = new Point(xtopLeft, ytopleft);
                        ucEdit.Size = new Size(Captain_xTop + iTextRealUse, 17);
                        ucEdit.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                        ucEdit.UcTableName = dr["REF_TABLE"].ToString();
                        ucEdit.UcDisplayMember = dr["REF_FIELD_NAME"].ToString();
                        ucEdit.UcValueMember = dr["REF_FIELD_VALUE"].ToString();
                        ucEdit.UcUser = dr["Get_User_Flag"].ToString().ToLower();
                        ucEdit.InitItme("");

                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                            ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                        else
                            ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();

                        ucEdit.TabIndex = tabIndex_xTop;
                        ucEdit.UcProperties.TextEditStyle = TextEditStyles.Standard;
                        xtopLeft += ucEdit.Width + disX;//横向布局控件


                        plTop.Controls.Add(ucEdit);
                        y = ucEdit.Height;
                        tabIndex_xTop++;

                        iChangeRow++;
                        if (iChangeRow % 4 == 0)
                        {
                            iYAddDis++;

                            if (iYAddDis <= xtopAddPanelCount)
                            {
                                if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                {
                                    ytopleft += y + disY * 2;//横向布局控件
                                    xtopLeft = 2;//横向布局控件
                                    plTop.Height = ytopleft + y + disY * 4;
                                }
                                else
                                {
                                    if (xtopAddPanelMod != 0)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                }

                            }



                        }
                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "datetime")
                    {
                        if (dr["DATATIME_FLAG"].ToString().ToLower() == "true")
                        {
                            Lamex.Controls.ucDateEdit ucEdit = new Controls.ucDateEdit();
                            ucEdit.Caption = FiledName + "(≥)" + "： ";
                            ucEdit.CaptionVisible = true;
                            ucEdit.CaptionWidth = Captain_xTop;
                            ucEdit.Location = new Point(xtopLeft, ytopleft);
                            ucEdit.Size = new Size(Captain_xTop + iTextRealUse, 17);
                            ucEdit.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            ucEdit.UcFilter = false;
                            ucEdit.UcUseType = true;

                            if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                                ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                            else
                                ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();
                            ucEdit.TabIndex = tabIndex_xTop;
                            xtopLeft += ucEdit.Width + disX;//横向布局控件

                            ucEdit.Text = "";
                            plTop.Controls.Add(ucEdit);
                            y = ucEdit.Height;
                            tabIndex_xTop++;

                            iChangeRow++;
                            if (iChangeRow % 4 == 0)
                            {
                                iYAddDis++;
                                if (iYAddDis <= xtopAddPanelCount)
                                {

                                    if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                    else
                                    {
                                        if (xtopAddPanelMod != 0)
                                        {
                                            ytopleft += y + disY * 2;//横向布局控件
                                            xtopLeft = 2;//横向布局控件
                                            plTop.Height = ytopleft + y + disY * 4;
                                        }
                                    }

                                }



                            }

                            Lamex.Controls.ucDateEdit ucEdit_end = new Controls.ucDateEdit();
                            ucEdit_end.Caption = FiledName + "(≤)" + "： ";
                            ucEdit_end.CaptionVisible = true;
                            ucEdit_end.CaptionWidth = Captain_xTop;
                            ucEdit_end.Location = new Point(xtopLeft, ytopleft);
                            ucEdit_end.Size = new Size(Captain_xTop + iTextRealUse, 17);
                            ucEdit_end.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            ucEdit_end.UcFilter = true;
                            ucEdit_end.UcUseType = true;
                            if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                                ucEdit_end.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                            else
                                ucEdit_end.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();
                            ucEdit_end.TabIndex = tabIndex_xTop;
                            xtopLeft += ucEdit_end.Width + disX;//横向布局控件

                            ucEdit_end.Text = "";
                            plTop.Controls.Add(ucEdit_end);
                            y = ucEdit_end.Height;
                            tabIndex_xTop++;
                            iChangeRow++;
                            if (iChangeRow % 4 == 0)
                            {
                                iYAddDis++;

                                if (iYAddDis <= xtopAddPanelCount)
                                {
                                    if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                    else
                                    {
                                        if (xtopAddPanelMod != 0)
                                        {
                                            ytopleft += y + disY * 2;//横向布局控件
                                            xtopLeft = 2;//横向布局控件
                                            plTop.Height = ytopleft + y + disY * 4;
                                        }
                                    }

                                }



                            }
                        }
                        else
                        {
                            Lamex.Controls.ucDateEdit ucEdit = new Controls.ucDateEdit();
                            ucEdit.Caption = FiledName + "： ";
                            ucEdit.CaptionVisible = true;
                            ucEdit.CaptionWidth = Captain_xTop;
                            ucEdit.Location = new Point(xtopLeft, ytopleft);
                            ucEdit.Size = new Size(Captain_xTop + iTextRealUse, 17);
                            ucEdit.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            ucEdit.UcFilter = false;
                            ucEdit.UcUseType = false;
                            if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                                ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                            else
                                ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();
                            ucEdit.TabIndex = tabIndex_xTop;
                            xtopLeft += ucEdit.Width + disX;//横向布局控件

                            ucEdit.Text = "";
                            plTop.Controls.Add(ucEdit);
                            y = ucEdit.Height;
                            tabIndex_xTop++;

                            iChangeRow++;
                            if (iChangeRow % 4 == 0)
                            {
                                iYAddDis++;

                                if (iYAddDis <= xtopAddPanelCount)
                                {
                                    if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                    else
                                    {
                                        if (xtopAddPanelMod != 0)
                                        {
                                            ytopleft += y + disY * 2;//横向布局控件
                                            xtopLeft = 2;//横向布局控件
                                            plTop.Height = ytopleft + y + disY * 4;
                                        }
                                    }

                                }



                            }
                        }



                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "checkedit")
                    {
                        Lamex.Controls.ucComboBoxEdit ucEdit = new Controls.ucComboBoxEdit();
                        ucEdit.Properties.Items.Clear();
                        ucEdit.Caption = FiledName + "： ";
                        ucEdit.CaptionVisible = true;
                        ucEdit.CaptionWidth = Captain_xTop;
                        ucEdit.Location = new Point(xtopLeft, ytopleft);
                        ucEdit.Size = new Size(Captain_xTop + iTextRealUse, 17);
                        ucEdit.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                            ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                        else
                            ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();

                        ucEdit.TabIndex = tabIndex_xTop;
                        xtopLeft += ucEdit.Width + disX;//横向布局控件

                        plTop.Controls.Add(ucEdit);
                        y = ucEdit.Height;
                        tabIndex_xTop++;
                        iChangeRow++;
                        if (iChangeRow % 4 == 0)
                        {
                            iYAddDis++;

                            if (iYAddDis <= xtopAddPanelCount)
                            {
                                if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                {
                                    ytopleft += y + disY * 2;//横向布局控件
                                    xtopLeft = 2;//横向布局控件
                                    plTop.Height = ytopleft + y + disY * 4;
                                }
                                else
                                {
                                    if (xtopAddPanelMod != 0)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                }

                            }

                        }
                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "dateedit")
                    {
                        if (dr["DATATIME_FLAG"].ToString().ToLower() == "true")
                        {
                            Lamex.Controls.ucDate ucEdit = new Controls.ucDate();
                            ucEdit.Caption = FiledName + "(≥)" + "： ";
                            ucEdit.CaptionVisible = true;
                            ucEdit.CaptionWidth = Captain_xTop;
                            ucEdit.Location = new Point(xtopLeft, ytopleft);
                            ucEdit.Size = new Size(Captain_xTop + iTextRealUse, 17);
                            ucEdit.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            ucEdit.UcFilter = false;
                            ucEdit.UcUseType = true;

                            ucEdit.UcEditValue = DateTime.MaxValue.ToString("yyyyy-MM-dd");
                            //ucEdit.initList();

                            //ucEdit.UcEditValue = DateTime.MaxValue.ToString("yyyyy-MM-dd");
                            //ucEdit.initList();


                            if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                                ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                            else
                                ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();
                            ucEdit.TabIndex = tabIndex_xTop;
                            xtopLeft += ucEdit.Width + disX;//横向布局控件

                            ucEdit.Text = "";

                            plTop.Controls.Add(ucEdit);

                            y = ucEdit.Height;
                            tabIndex_xTop++;

                            iChangeRow++;
                            if (iChangeRow % 4 == 0)
                            {
                                iYAddDis++;
                                if (iYAddDis <= xtopAddPanelCount)
                                {

                                    if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                    else
                                    {
                                        if (xtopAddPanelMod != 0)
                                        {
                                            ytopleft += y + disY * 2;//横向布局控件
                                            xtopLeft = 2;//横向布局控件
                                            plTop.Height = ytopleft + y + disY * 4;
                                        }
                                    }

                                }



                            }

                            Lamex.Controls.ucDate ucEdit_end = new Controls.ucDate();
                            ucEdit_end.Caption = FiledName + "(≤)" + "： ";
                            ucEdit_end.CaptionVisible = true;
                            ucEdit_end.CaptionWidth = Captain_xTop;
                            ucEdit_end.Location = new Point(xtopLeft, ytopleft);
                            ucEdit_end.Size = new Size(Captain_xTop + iTextRealUse, 17);
                            ucEdit_end.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            ucEdit_end.UcFilter = true;
                            ucEdit_end.UcUseType = true;
                            //ucEdit.initList();
                            if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                                ucEdit_end.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                            else
                                ucEdit_end.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();
                            ucEdit_end.TabIndex = tabIndex_xTop;
                            xtopLeft += ucEdit_end.Width + disX;//横向布局控件

                            ucEdit_end.Text = "";
                            plTop.Controls.Add(ucEdit_end);
                            y = ucEdit_end.Height;
                            tabIndex_xTop++;
                            iChangeRow++;
                            if (iChangeRow % 4 == 0)
                            {
                                iYAddDis++;

                                if (iYAddDis <= xtopAddPanelCount)
                                {
                                    if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                    else
                                    {
                                        if (xtopAddPanelMod != 0)
                                        {
                                            ytopleft += y + disY * 2;//横向布局控件
                                            xtopLeft = 2;//横向布局控件
                                            plTop.Height = ytopleft + y + disY * 4;
                                        }
                                    }

                                }



                            }
                        }
                        else
                        {
                            Lamex.Controls.ucDate ucEdit = new Controls.ucDate();
                            ucEdit.Caption = FiledName + "： ";
                            ucEdit.CaptionVisible = true;
                            ucEdit.CaptionWidth = Captain_xTop;
                            ucEdit.Location = new Point(xtopLeft, ytopleft);
                            ucEdit.Size = new Size(Captain_xTop + iTextRealUse, 17);
                            ucEdit.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            ucEdit.UcFilter = false;
                            ucEdit.UcUseType = false;
                            if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                                ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                            else
                                ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();
                            ucEdit.TabIndex = tabIndex_xTop;
                            xtopLeft += ucEdit.Width + disX;//横向布局控件

                            ucEdit.Text = "";
                            plTop.Controls.Add(ucEdit);
                            y = ucEdit.Height;
                            tabIndex_xTop++;

                            iChangeRow++;
                            if (iChangeRow % 4 == 0)
                            {
                                iYAddDis++;

                                if (iYAddDis <= xtopAddPanelCount)
                                {
                                    if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                    else
                                    {
                                        if (xtopAddPanelMod != 0)
                                        {
                                            ytopleft += y + disY * 2;//横向布局控件
                                            xtopLeft = 2;//横向布局控件
                                            plTop.Height = ytopleft + y + disY * 4;
                                        }
                                    }

                                }



                            }
                        }



                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "pictrueedit")
                    {
                        Lamex.Controls.ucPictrueEdit ucEdit = new Controls.ucPictrueEdit();
                        ucEdit.Caption = FiledName + "： ";
                        ucEdit.CaptionVisible = true;
                        ucEdit.CaptionWidth = Captain_xTop;
                        ucEdit.Location = new Point(xtopLeft, ytopleft);
                        ucEdit.Size = new Size(Captain_xTop + iTextRealUse, 17);
                        ucEdit.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                            ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["FORM_TABLE_NAME"].ToString() + '.' + dr["WRITE_FIELD_NAME"].ToString();
                        else
                            ucEdit.Tag = dr["DATABASE_NAME"].ToString() + ".dbo." + dr["REF_TABLE"].ToString() + '.' + dr["REF_FIELD_VALUE"].ToString();
                        ucEdit.TabIndex = tabIndex_xTop;
                        xtopLeft += ucEdit.Width + disX;//横向布局控件


                        plTop.Controls.Add(ucEdit);
                        y = ucEdit.Height;
                        tabIndex_xTop++;

                        iChangeRow++;
                        if (iChangeRow % 4 == 0)
                        {
                            iYAddDis++;
                            if (iYAddDis <= xtopAddPanelCount)
                            {
                                if (xtopAddPanelMod == 0 && xtopAddPanelCount > iYAddDis)
                                {
                                    ytopleft += y + disY * 2;//横向布局控件
                                    xtopLeft = 2;//横向布局控件
                                    plTop.Height = ytopleft + y + disY * 4;
                                }
                                else
                                {
                                    if (xtopAddPanelMod != 0)
                                    {
                                        ytopleft += y + disY * 2;//横向布局控件
                                        xtopLeft = 2;//横向布局控件
                                        plTop.Height = ytopleft + y + disY * 4;
                                    }
                                }

                            }
                        }
                    }
                }

                //右边界面处理

                if (true)
                {
                    if (dr["CTRL_TYPE"].ToString().ToLower() == "textedit")
                    {
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                        {
                            Lamex.Controls.ucTextEdit uc = new Controls.ucTextEdit();
                            uc.Caption = FiledName + "： ";
                            uc.CaptionWidth = Captain_xLeft - 20;
                            uc.Location = new Point(xleftCenter, yLeft);
                            uc.Size = new Size(uc.CaptionWidth + ixLeftTextRealUse, 17);
                            uc.TabIndex = tabIndex_xLeft;


                            uc.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            uc.UcUser = dr["Get_User_Flag"].ToString().ToLower();
                            int lg = uc.Width;
                            if (dr["NO_BLANK_FLAG"].ToString().ToLower() == "true")//要显示提示
                            {
                                uc.UcErrortip = alterMessage;
                            }
                            if (dr["RAED_ONLY"].ToString().ToLower() == "true")
                                uc.Tag = "true";
                            else
                                uc.Tag = "false";
                            if (dr["CTRL_VALUE_TYPE"].ToString().ToLower() == "int")
                            {
                                uc.TypeList = DataTypeList.ToDictEnum<Lamex.Controls.ucTextEdit.ComboxListEdit>("Int");
                                uc.Text = "";
                            }
                            else if (dr["CTRL_VALUE_TYPE"].ToString().ToLower().Contains("decimal"))
                            {
                                uc.TypeList = DataTypeList.ToDictEnum<Lamex.Controls.ucTextEdit.ComboxListEdit>("Decimal");
                                uc.UcRightToLeft = RightToLeft.Yes;
                            }


                            if (dr["DUPL_CHECK_FLAG"].ToString().ToLower() == "true")
                                uc.UcFlterEditFlag = "true";
                            else
                                uc.UcFlterEditFlag = "false";
                            if (dr["ENABLED"].ToString().ToLower() == "true")
                                uc.UcEnabled = true;
                            else
                                uc.UcEnabled = false;

                            plEditPanel.Controls.Add(uc);
                            yLeft += uc.Height + disLeft;
                            tabIndex_xLeft++;
                        }
                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "combobox")
                    {
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                        {

                            Lamex.Controls.ucComboBoxEdit uc = new Controls.ucComboBoxEdit();
                            uc.Properties.Items.Clear();
                            uc.Caption = FiledName + "： ";
                            uc.CaptionWidth = Captain_xLeft - 20;
                            uc.Location = new Point(xleftCenter, yLeft);
                            uc.Size = new Size(uc.CaptionWidth + ixLeftTextRealUse, 17);
                            uc.TabIndex = tabIndex_xLeft;
                            uc.Comb.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
                            uc.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            uc.UcUser = dr["Get_User_Flag"].ToString().ToLower();
                            int lg = uc.Width;
                            if (dr["NO_BLANK_FLAG"].ToString().ToLower() == "true")//要显示提示
                            {
                                uc.UcErrortip = alterMessage;
                            }
                            if (dr["RAED_ONLY"].ToString().ToLower() == "true")
                                uc.Tag = "true";
                            else
                                uc.Tag = "false";
                            if (dr["DUPL_CHECK_FLAG"].ToString().ToLower() == "true")
                                uc.UcFlterEditFlag = "true";
                            else
                                uc.UcFlterEditFlag = "false";
                            if (dr["ENABLED"].ToString().ToLower() == "true")
                                uc.UcEnabled = true;
                            else
                                uc.UcEnabled = false;

                            //uc.UcErrortip = alterMessage;

                            plEditPanel.Controls.Add(uc);
                            yLeft += uc.Height + disLeft;
                            tabIndex_xLeft++;
                            DataTable dtList = BaseBuildSql.GetDataTableBySql(" select * from Sys_ControlValueOption where FIELD_NAME='" + dr["CTRL_EN_NAME"].ToString() + "'");
                            foreach (DataRow d in dtList.Rows)
                            {
                                string[] sPlitList = d["FIELD_VALUE_OPTION"].ToString().Split(',');
                                foreach (string s in sPlitList)
                                    uc.Properties.Items.Add(s);
                            }
                        }
                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "lookupedit")
                    {
                        DataTable dtList = BaseBuildSql.GetDataTableBySql(" select " + dr["REF_FIELD_NAME"].ToString() + "," + dr["REF_FIELD_VALUE"].ToString() + " from " + dr["REF_TABLE"].ToString() + "");
                        Lamex.Controls.ucLookUpEdit uc = new Controls.ucLookUpEdit();
                        uc.Caption = FiledName + "： ";
                        uc.CaptionVisible = true;
                        uc.CaptionWidth = Captain_xLeft - 20;
                        uc.Location = new Point(xleftCenter, yLeft);
                        uc.Size = new Size(uc.CaptionWidth + ixLeftTextRealUse, 17);
                        uc.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                        uc.UcTableName = dr["REF_TABLE"].ToString();
                        uc.UcDisplayMember = dr["REF_FIELD_VALUE"].ToString();
                        uc.UcValueMember = dr["REF_FIELD_NAME"].ToString();
                        uc.UcUser = dr["Get_User_Flag"].ToString().ToLower();

                        uc.InitItme("");
                        int lg = uc.Width;
                        if (dr["RAED_ONLY"].ToString().ToLower() == "true")
                            uc.Tag = "true";
                        else
                            uc.Tag = "false";

                        if (dr["DUPL_CHECK_FLAG"].ToString().ToLower() == "true")
                            uc.UcFlterEditFlag = "true";
                        else
                            uc.UcFlterEditFlag = "false";
                        if (dr["ENABLED"].ToString().ToLower() == "true")
                            uc.UcEnabled = true;
                        else
                            uc.UcEnabled = false;

                        //uc.UcErrortip = alterMessage;

                        plEditPanel.Controls.Add(uc);
                        yLeft += uc.Height + disLeft;
                        tabIndex_xLeft++;
                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "datetime")
                    {
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                        {
                            Lamex.Controls.ucDateEdit uc = new Controls.ucDateEdit();
                            uc.Caption = FiledName + "： ";
                            uc.CaptionWidth = Captain_xLeft - 20;
                            uc.Location = new Point(xleftCenter, yLeft);
                            uc.Size = new Size(uc.CaptionWidth + ixLeftTextRealUse, 17);
                            uc.TabIndex = tabIndex_xLeft;
                            uc.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            uc.UcProperties.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            uc.UcProperties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                            uc.UcProperties.EditFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            uc.UcProperties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;

                            if (dr["NO_BLANK_FLAG"].ToString().ToLower() == "true")//要显示提示
                            {
                                uc.UcErrortip = alterMessage;
                            }
                            if (dr["RAED_ONLY"].ToString().ToLower() == "true")
                                uc.Tag = "true";
                            else
                                uc.Tag = "false";
                            if (dr["DUPL_CHECK_FLAG"].ToString().ToLower() == "true")
                                uc.UcFlterEditFlag = "true";
                            else
                                uc.UcFlterEditFlag = "false";
                            if (dr["DATEMAX_FLAG"].ToString().ToLower() == "true")
                            {
                                uc.UcMaxFlag = "true";
                                uc.UcEditValue = DateTime.MaxValue;
                            }
                            else
                            {
                                uc.UcMaxFlag = "false";
                                uc.UcEditValue = DateTime.Now;
                            }
                            if (dr["ENABLED"].ToString().ToLower() == "true")
                                uc.UcEnabled = true;
                            else
                                uc.UcEnabled = false;

                            if (dr["GET_SYSTIME_FLAG"].ToString().ToLower() == "true")
                            {
                                uc.UcEditValue = DateTime.Now;
                            }



                            //uc.UcErrortip = alterMessage;

                            plEditPanel.Controls.Add(uc);
                            yLeft += uc.Height + disLeft;
                            tabIndex_xLeft++;
                        }
                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "dateedit")
                    {
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                        {
                            Lamex.Controls.ucDate uc = new Controls.ucDate();
                            uc.Caption = FiledName + "： ";
                            uc.CaptionWidth = Captain_xLeft - 20;
                            uc.Location = new Point(xleftCenter, yLeft);
                            uc.Size = new Size(uc.CaptionWidth + ixLeftTextRealUse, 17);
                            uc.TabIndex = tabIndex_xLeft;
                            uc.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            //uc.UcProperties.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            //uc.UcProperties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                            //uc.UcProperties.EditFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
                            //uc.UcProperties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;

                            if (dr["NO_BLANK_FLAG"].ToString().ToLower() == "true")//要显示提示
                            {
                                uc.UcErrortip = alterMessage;
                            }
                            if (dr["RAED_ONLY"].ToString().ToLower() == "true")
                                uc.Tag = "true";
                            else
                                uc.Tag = "false";
                            if (dr["DUPL_CHECK_FLAG"].ToString().ToLower() == "true")
                                uc.UcFlterEditFlag = "true";
                            else
                                uc.UcFlterEditFlag = "false";
                            uc.UcEditValue = null;
                            uc.Text = "";


                            if (dr["DATEMAX_FLAG"].ToString().ToLower() == "true")
                            {
                                uc.UcMaxFlag = "true";
                                //uc.UcEditValue = DateTime.MaxValue.ToString("yyyyy-MM-dd");

                            }
                            else
                            {
                                uc.UcMaxFlag = "false";
                                //uc.UcEditValue = DateTime.Now.ToString("yyyyy-MM-dd"); ;

                            }
                            if (dr["ENABLED"].ToString().ToLower() == "true")
                                uc.UcEnabled = true;
                            else
                                uc.UcEnabled = false;

                            if (dr["GET_SYSTIME_FLAG"].ToString().ToLower() == "true")
                            {
                                uc.UcEditValue = DateTime.Now.ToString("yyyyy-MM-dd"); ;
                            }



                            //uc.UcErrortip = alterMessage;

                            plEditPanel.Controls.Add(uc);
                            uc.UcEditValue = null;
                            uc.Text = "";
                            yLeft += uc.Height + disLeft;
                            tabIndex_xLeft++;
                        }
                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "memoedit")
                    {
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                        {
                            Lamex.Controls.ucMemoEdit uc = new Controls.ucMemoEdit();
                            uc.Caption = FiledName + "： ";
                            uc.CaptionWidth = Captain_xLeft - 20;
                            uc.Location = new Point(xleftCenter, yLeft);
                            uc.Size = new Size(uc.CaptionWidth + ixLeftTextRealUse, 17 * 3);
                            uc.TabIndex = tabIndex_xLeft;

                            uc.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            uc.UcUser = dr["Get_User_Flag"].ToString().ToLower();
                            int lg = uc.Width;
                            if (dr["NO_BLANK_FLAG"].ToString().ToLower() == "true")//要显示提示
                            {
                                uc.UcErrortip = alterMessage;
                            }
                            if (dr["RAED_ONLY"].ToString().ToLower() == "true")
                                uc.Tag = "true";
                            else
                                uc.Tag = "false";
                            if (dr["CTRL_VALUE_TYPE"].ToString().ToLower() == "int")
                            {
                                uc.TypeList = DataTypeList.ToDictEnum<Lamex.Controls.ucMemoEdit.ComboxListEdit>("Int");
                            }
                            else if (dr["CTRL_VALUE_TYPE"].ToString().ToLower().Contains("decimal"))
                            {
                                uc.TypeList = DataTypeList.ToDictEnum<Lamex.Controls.ucMemoEdit.ComboxListEdit>("Decimal");
                                uc.UcRightToLeft = RightToLeft.Yes;
                            }


                            if (dr["DUPL_CHECK_FLAG"].ToString().ToLower() == "true")
                                uc.UcFlterEditFlag = "true";
                            else
                                uc.UcFlterEditFlag = "false";
                            if (dr["ENABLED"].ToString().ToLower() == "true")
                                uc.UcEnabled = true;
                            else
                                uc.UcEnabled = false;

                            plEditPanel.Controls.Add(uc);
                            yLeft += uc.Height;
                            tabIndex_xLeft++;
                        }
                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "checkedit")
                    {
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                        {
                            Lamex.Controls.ucCheckEdit uc = new Controls.ucCheckEdit();
                            uc.Caption = FiledName + "： ";
                            uc.CaptionWidth = Captain_xLeft - 20;
                            uc.Location = new Point(xleftCenter, yLeft);
                            uc.Size = new Size(uc.CaptionWidth + ixLeftTextRealUse, 17);
                            uc.TabIndex = tabIndex_xLeft;

                            uc.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            uc.UcUser = dr["Get_User_Flag"].ToString().ToLower();
                            int lg = uc.Width;
                            if (dr["NO_BLANK_FLAG"].ToString().ToLower() == "true")//要显示提示
                            {
                                uc.UcErrortip = alterMessage;
                            }
                            if (dr["RAED_ONLY"].ToString().ToLower() == "true")
                                uc.Tag = "true";
                            else
                                uc.Tag = "false";
                            if (dr["DUPL_CHECK_FLAG"].ToString().ToLower() == "true")
                                uc.UcFlterEditFlag = "true";
                            else
                                uc.UcFlterEditFlag = "false";
                            if (dr["ENABLED"].ToString().ToLower() == "true")
                                uc.UcEnabled = true;
                            else
                                uc.UcEnabled = false;

                            plEditPanel.Controls.Add(uc);
                            yLeft += uc.Height + disLeft;
                            tabIndex_xLeft++;
                        }
                    }
                    else if (dr["CTRL_TYPE"].ToString().ToLower() == "pictrueedit")
                    {
                        if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                        {
                            Lamex.Controls.ucPictrueEdit uc = new Controls.ucPictrueEdit();
                            uc.UcDoubleClick += new EventHandler(uc_UcDoubleClick);
                            uc.Caption = FiledName + "： ";
                            uc.CaptionWidth = Captain_xLeft - 20;
                            uc.Location = new Point(xleftCenter, yLeft);
                            uc.Size = new Size(uc.CaptionWidth + ixLeftTextRealUse, 17 * 4);
                            uc.TabIndex = tabIndex_xLeft;

                            uc.Name = dr["WRITE_FIELD_NAME"].ToString().Trim();
                            uc.UcUser = dr["Get_User_Flag"].ToString().ToLower();
                            int lg = uc.Width;
                            if (dr["NO_BLANK_FLAG"].ToString().ToLower() == "true")//要显示提示
                            {
                                uc.UcErrortip = alterMessage;
                            }
                            if (dr["RAED_ONLY"].ToString().ToLower() == "true")
                                uc.Tag = "true";
                            else
                                uc.Tag = "false";
                            uc.UcReadOnly = true;

                            if (dr["DUPL_CHECK_FLAG"].ToString().ToLower() == "true")
                                uc.UcFlterEditFlag = "true";
                            else
                                uc.UcFlterEditFlag = "false";
                            if (dr["ENABLED"].ToString().ToLower() == "true")
                                uc.UcEnabled = true;
                            else
                                uc.UcEnabled = false;

                            plEditPanel.Controls.Add(uc);
                            yLeft += uc.Height + disLeft;
                            tabIndex_xLeft++;
                        }
                    }
                }

            }
            //计总行数

            if (true)
            {
                if (yLeft > 22)
                {
                    //Lamex.Controls.ucDateEdit uc = new Controls.ucDateEdit();
                    //uc.Caption = "";
                    //uc.CaptionWidth = Captain_xLeft;
                    //uc.Location = new Point(xLeft, yLeft);
                    //uc.Size = new Size(Captain_xLeft + 100, 15);
                    //gcmIWCEBox.Controls.Add(uc);
                    ucSimpleButtion btn = new ucSimpleButtion();
                    //yLeft += btn.Height ;
                    //SimpleButton btn = new SimpleButton();
                    btn.Name = "btnSave";
                    btn.TextTitle = "保存";
                    btn.Location = new Point(Captain_xLeft - 20 + xleftCenter - 5, yLeft);
                    btn.UcClick += new EventHandler(btn_Click);
                    plEditPanel.Controls.Add(btn);
                }
            }
            if (IsFormEdit == 1)
            {
                plRight.Visible = true;
                plRight.AutoSize = false;
            }
            else
            {
                plRight.AutoSize = true;
                plRight.Visible = false;

            }

            gcViewMain.Columns[0].SummaryItem.DisplayFormat = "计数或汇总";
            gcViewMain.Columns[0].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom;//求和
            //gcViewMain.Columns[1].SummaryItem.DisplayFormat = "汇总";
            gcViewMain.Columns[1].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;//求和 by2020-10-27
            //gcmIWCEBox.
            this.gcViewMain.GridControl = this.gcView1;
            this.gcViewMain.Name = "gcViewMain";
            this.gcViewMain.OptionsView.ShowGroupPanel = true;


            gcViewMain.OptionsBehavior.ReadOnly = true;
            gcViewMain.OptionsBehavior.Editable = false;

        }
        private void frmBaseChildWinForm_TextChanged(object sender, EventArgs e)
        {
            ChangeLanguage();
        }


        private void ChangeLanguage()
        {

            if (dt == null) return;
            DataRow drow = dt.Select("1=1").FirstOrDefault();
            if (Lamex.Common.Loginer.CurrentUser.ChangeLanguage == 0)
                this.Text = drow["FORM_CN_NAME"].ToString().Trim();
            else
                this.Text = drow["FORM_EN_NAME"].ToString().Trim();

            gcChangeLanguate();
            SetControlLanguage.SetGridViewControlName(gcViewMain, dt);
            SetControlLanguage.SetControlName(plTop, dt);
            SetControlLanguage.SetGcControlName(gcmIWCEBox, dt);

        }
        private void gcChangeLanguate()
        {
            if (Loginer.CurrentUser.ChangeLanguage == 0)
            {
                if (isEdit == "")
                    gcmIWCEBox.Text = gcCNBoxAll;
                else if (isEdit == "New")
                    gcmIWCEBox.Text = gcCNAdd;
                else if (isEdit == "Edit")
                    gcmIWCEBox.Text = gcCNEdit;



            }
            else
            {
                if (isEdit == "")
                    gcmIWCEBox.Text = gcENBoxAll;
                else if (isEdit == "New")
                    gcmIWCEBox.Text = gcENAdd;
                else if (isEdit == "Edit")
                    gcmIWCEBox.Text = gcENEdit;

            }
        }
        private GridColumn ColumeName(string colName)
        {
            GridColumn gridColumn = null;
            foreach (GridColumn c in gcViewMain.Columns)
            {
                if (c.FieldName == colName) return c;
            }
            return gridColumn;
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        string ErrorMsg = "";
        public override void DoView(IButtonInfo sender)
        {
            try
            {
                string strWhere = " where 1=1 ";
                string strJoinName = "";
                string sql = " select ";
                string PredictName = dt.Rows[0]["DATABASE_NAME"].ToString();
                foreach (DataRow dr in dt.Rows)
                {
                    if (!string.IsNullOrEmpty(dr["WRITE_FIELD_NAME"].ToString()))
                        sql += dr["DATABASE_NAME"].ToString() + "." + "dbo." + dr["FORM_TABLE_NAME"].ToString() + "." + dr["WRITE_FIELD_NAME"].ToString() + ",";
                    else
                        sql += dr["DATABASE_NAME"].ToString() + "." + "dbo." + dr["REF_TABLE"].ToString() + "." + dr["REF_FIELD_VALUE"].ToString() + ",";
                    if (!string.IsNullOrEmpty(dr["REF_FIELD_VALUE"].ToString()) && !string.IsNullOrEmpty(dr["MAIN_FEILD_NAME"].ToString()))
                    {
                        strJoinName += " LEFT JOIN " + dr["DATABASE_NAME"].ToString() + "." + "dbo." + dr["REF_TABLE"].ToString() + " ON " + dr["DATABASE_NAME"].ToString() + "." + "dbo." + dr["FORM_TABLE_NAME"].ToString() + "." + dr["MAIN_FEILD_NAME"].ToString() + "=" + dr["DATABASE_NAME"].ToString() + "." + "dbo." + dr["REF_TABLE"].ToString() + "." + dr["REF_FIELD_NAME"].ToString() + "\r\n";
                    }

                }
                sql = sql.Trim(',');
                sql += " from " + PredictName + "." + "dbo." + dtName + "\r\n";
                sql += strJoinName;






                foreach (Control c in plTop.Controls)
                {
                    if (c is ucTextEdit)
                    {
                        ucTextEdit uc = c as ucTextEdit;
                        if (!string.IsNullOrEmpty(uc.Text))
                        {
                            strWhere += " and " + uc.Tag.ToString() + " like '%" + uc.Text + "%'";
                        }

                    }
                    else if (c is ucComboBoxEdit)
                    {
                        ucComboBoxEdit uc = c as ucComboBoxEdit;
                        if (!string.IsNullOrEmpty(uc.Text))
                        {
                            strWhere += " and " + uc.Tag.ToString() + " like '%" + uc.Text + "%'";
                        }
                    }
                    else if (c is ucLookUpEdit)
                    {
                        ucLookUpEdit uc = c as ucLookUpEdit;
                        if (!string.IsNullOrEmpty(uc.Text))
                        {
                            strWhere += " and " + uc.Tag.ToString() + " like '%" + uc.Text + "%'";
                        }
                    }
                    else if (c is ucDateEdit)
                    {
                        ucDateEdit uc = c as ucDateEdit;
                        if (!string.IsNullOrEmpty(uc.Text))
                        {
                            if (uc.UcUseType == true)
                            {
                                if (uc.UcFilter == false)
                                    strWhere += " and " + uc.Tag.ToString() + " >= '" + uc.Text + "'";
                                else
                                    strWhere += " and " + uc.Tag.ToString() + " <= '" + uc.Text + "'";
                            }
                            else
                            {
                                //strWhere += " and  Convert(nvarchar(10), " + uc.Tag.ToString() + ",120) = Convert(nvarchar(10), '" + uc.Text + "',120)";
                                DateTime datetime = Convert.ToDateTime(uc.Text);
                                string startDate = datetime.ToString("yyyy-MM-dd") + " 00:00:00";
                                string endDate = datetime.ToString("yyyy-MM-dd") + " 23:59:59";
                                strWhere += " and  " + uc.Tag.ToString() + " between '" + startDate + "' and '" + endDate + "'";
                            }
                        }
                    }
                    else if (c is ucDate)
                    {
                        ucDate uc = c as ucDate;
                        if (!string.IsNullOrEmpty(uc.Text))
                        {
                            if (uc.UcUseType == true)
                            {
                                if (uc.UcFilter == false)
                                    strWhere += " and  " + uc.Tag.ToString() + " >= '" + uc.Text + "'";
                                else
                                    strWhere += " and " + uc.Tag.ToString() + " <= '" + uc.Text + "'";
                            }
                            else
                            {
                                //strWhere += " and  Convert(nvarchar(10), " + uc.Tag.ToString() + ",120) = Convert(nvarchar(10), '" + uc.Text + "',120)";
                                DateTime datetime = Convert.ToDateTime(uc.Text);
                                string startDate = datetime.ToString("yyyy-MM-dd") + " 00:00:00";
                                string endDate = datetime.ToString("yyyy-MM-dd") + " 23:59:59";
                                strWhere += " and  " + uc.Tag.ToString() + " between '" + startDate + "' and '" + endDate + "'";
                            }
                        }
                    }
                }
                if (string.IsNullOrEmpty(strWhere))
                {
                    if (Loginer.CurrentUser.ChangeLanguage == 0)
                    {
                        XtraMessageBox.Show("无查询条件!");
                    }
                    else
                    {
                        XtraMessageBox.Show("No Query Condition!");
                    }
                    return;
                }
                sql = sql + strWhere;
                ErrorMsg = "";
                ErrorMsg = sql;
                gcViewMain.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CellSelect;
                gcViewMain.OptionsBehavior.Editable = false;
                gcViewMain.OptionsBehavior.ReadOnly = false;
                gcViewMain.OptionsView.ColumnAutoWidth = false;
                gcViewMain.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
                //gcViewMain.Appearance.Row.TextOptions.HAlignment= HorzAlignment.Center;
                //gcViewMain.BestFitColumns();
                int iplLength = plLeftView.Width / 5;
                List<string> fieldList = new List<string>();
                DataTable dTable = BaseBuildSql.GetDataTableBySql(sql);
                foreach (DataColumn c in dTable.Columns)
                {
                    int colLenght = GetMaxLength(dTable, c.ColumnName);//cacurlate Max Column Content need the witdth

                    if (colLenght * 11 > iplLength)
                        fieldList.Add(c.ColumnName);
                }
                gcView1.DataSource = dTable;
                for (int i = 0; i < gcViewMain.Columns.Count; i++)
                {

                    string name = this.gcViewMain.Columns[i].FieldName;
                    string field = fieldList.Where(p => p == name).FirstOrDefault();
                    if (string.IsNullOrEmpty(field))
                    {

                        this.gcViewMain.Columns[i].BestFit();//autocolumn width    

                    }
                    else
                    {
                        //this.gcViewMain.BestFitColumns();
                        this.gcViewMain.Columns[i].Width = iplLength;//1/5 gridview，setting 1/5 gridview
                    }
                }


                if (dTable.Rows.Count != 0)
                {
                    gcViewMain.FocusedRowHandle = iCurrentRow;
                    gcViewMain.Appearance.SelectedRow.BackColor = Color.Yellow;
                    gcViewMain.Appearance.FocusedRow.BackColor = Color.Yellow;
                }
                dtImport = new DataTable();
                dtImport = dTable.Clone();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ErrorMsg + ex.Message);
            }
            base.DoView(sender);
        }

        public int GetMaxLength(DataTable dt, string colName)
        {
            DataTable dtMaxLength = dt.Copy();
            DataColumn maxLengthColumn = new DataColumn();//从新定义一列，用来存放内容的长度
            maxLengthColumn.ColumnName = "MaxLength";//新列列名
            maxLengthColumn.DataType = typeof(Int32);//新列类型
            //其中name为列名，用到的函数为len
            maxLengthColumn.Expression = "len(convert(" + colName + ",'System.String'))";//len表达式用来计算长度
            dtMaxLength.Columns.Add(maxLengthColumn);
            //用到的函数为Max
            object maxLength = dtMaxLength.Compute("Max(MaxLength)", "");//max表达式进行计算
            dtMaxLength.Columns.Remove(maxLengthColumn);//移除新增列,不破坏原有DatatTable
            if (string.IsNullOrEmpty(maxLength.ToString()))
                maxLength = 0;
            return Convert.ToInt32(maxLength);
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        public override void DoAdd(IButtonInfo sender)
        {
            //string strWhere = "";
            //if(!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    string[] subName = Loginer.CurrentUser.Email.Split('@');
            //    //string str = subName[0].Replace('.',' ').Trim().ToUpper();
            //    strWhere += " and UPPER( AUTHORITY_USER_NAME) like '%" + subName[0].ToUpper() + "%'";
            //    strWhere += " and DATABASE_NAME='LamexMESManager' ";
            //    strWhere += " and TABLE_NAME='"+dtName+"' ";
            //}
            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    if (!BuildSqlHelper.IsExistList(strWhere))
            //    {
            //        XtraMessageBox.Show("非授权用户，操作未完成！");
            //        return;
            //    }
            //}
            //else
            //{
            //    XtraMessageBox.Show("非授权用户，操作未完成！");
            //    return;
            //}
            if (!BuildSqlHelper.IsExistList(dtName, dataBaseName)) return;
            plRight.Visible = true;
            //plRight.AutoSize = false;
            //txtmIEWCEditProcessCode.UcReadOnly = false;
            RetureControlStr.SetControlVaildValue(plEditPanel);
            isEdit = "New";
            gcChangeLanguate();

            base.DoAdd(sender);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        public override void DoEdit(IButtonInfo sender)
        {
            //string strWhere = "";
            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    string[] subName = Loginer.CurrentUser.Email.Split('@');
            //    //string str = subName[0].Replace('.',' ').Trim().ToUpper();
            //    strWhere += " and UPPER( AUTHORITY_USER_NAME) like '%" + subName[0].ToUpper() + "%'";
            //    strWhere += " and DATABASE_NAME='LamexMESManager' ";
            //    strWhere += " and TABLE_NAME='" + dtName + "' ";
            //}
            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    if (!BuildSqlHelper.IsExistList(strWhere))
            //    {
            //        XtraMessageBox.Show("非授权用户，操作未完成！");
            //        return;
            //    }
            //}
            //else
            //{
            //    XtraMessageBox.Show("非授权用户，操作未完成！");
            //    return;
            //}
            if (!BuildSqlHelper.IsExistList(dtName, dataBaseName)) return;

            if (gcViewMain.RowCount < 1)
            {
                if (Loginer.CurrentUser.ChangeLanguage == 0)
                    XtraMessageBox.Show("没有选中数据");
                else
                    XtraMessageBox.Show("No Choose Data");
                return;
            }
            plRight.Visible = true;
            //plRight.AutoSize = false;
            int iRow = gcViewMain.FocusedRowHandle;

            RetureControlStr.SetControlVaildValue(plEditPanel);
            RetureControlStr.SetControlValue(gcViewMain, plEditPanel, iRow, iType);
            isEdit = "Edit";
            gcChangeLanguate();


            base.DoEdit(sender);
        }


        public override void DoDelete(IButtonInfo sender)
        {
            //string strWhere = "";
            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    string[] subName = Loginer.CurrentUser.Email.Split('@');
            //    //string str = subName[0].Replace('.',' ').Trim().ToUpper();
            //    strWhere += " and UPPER( AUTHORITY_USER_NAME) like '%" + subName[0].ToUpper() + "%'";
            //    strWhere += " and DATABASE_NAME='LamexMESManager' ";
            //    strWhere += " and TABLE_NAME='" + dtName + "' ";
            //}
            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    if (!BuildSqlHelper.IsExistList(strWhere))
            //    {
            //        XtraMessageBox.Show("非授权用户，操作未完成！");
            //        return;
            //    }
            //}
            //else
            //{
            //    XtraMessageBox.Show("非授权用户，操作未完成！");
            //    return;
            //}
            try
            {
                if (!BuildSqlHelper.IsExistList(dtName, dataBaseName)) return;
                if (gcViewMain.DataRowCount < 1) return;
                if (string.IsNullOrEmpty(IsEidtWhere))
                {
                    XtraMessageBox.Show("未设置删除条件！");
                    return;
                }

                string Msg = "";
                if (Loginer.CurrentUser.ChangeLanguage == 0)
                    Msg = "是否要删除这条数据";
                else
                    Msg = " if you want to delete this data";
                if (DialogResult.Yes == XtraMessageBox.Show(Msg, "", MessageBoxButtons.YesNo))
                {

                    string sql = " delete  from  " + dtName + " where 1=1 " + IsEidtWhere;
                    if (BaseBuildSql.ExecuteNonQuery(sql) > 0)
                    {
                        if (Loginer.CurrentUser.ChangeLanguage == 0)
                            XtraMessageBox.Show("成功删除");
                        else
                            XtraMessageBox.Show("Delete successfully!");
                        iCurrentRow = iCurrentRow - 1;
                        DoView(null);
                    }
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
            base.DoDelete(sender);
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        public override void DoSave(IButtonInfo sender)
        {


            btn_Click(null, null);

            base.DoSave(sender);
        }
        public override void DoImport(IButtonInfo sender)
        {
            //string strWhere = "";
            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    string[] subName = Loginer.CurrentUser.Email.Split('@');
            //    //string str = subName[0].Replace('.',' ').Trim().ToUpper();
            //    strWhere += " and UPPER( AUTHORITY_USER_NAME) like '%" + subName[0].ToUpper() + "%'";
            //    strWhere += " and DATABASE_NAME='LamexMESManager' ";
            //    strWhere += " and TABLE_NAME='" + dtName + "' ";
            //}

            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    if (!BuildSqlHelper.IsExistList(strWhere))
            //    {
            //        XtraMessageBox.Show("非授权用户，操作未完成！");
            //        return;
            //    }
            //}
            //else
            //{
            //    XtraMessageBox.Show("非授权用户，操作未完成！");
            //    return;
            //}
            if (!BuildSqlHelper.IsExistList(dtName, dataBaseName)) return;
            FrmImport frm = new FrmImport(dtName,dtDatasource, dataBaseName);
            frm.ShowDialog();
            DoView(null);
            base.DoImport(sender);
        }
        public override void DoExport(IButtonInfo sender)
        {
            if (gcViewMain.RowCount < 1)
            {
                if (Loginer.CurrentUser.ChangeLanguage == 0)
                    XtraMessageBox.Show("没有选中数据");
                else
                    XtraMessageBox.Show("No Choose Data");
                return;
            }
            string path = @"D:\MESTemp";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            //frmSelectExport frm = new frmSelectExport(gcViewMain,path);

            //frm.ShowDialog();


            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.InitialDirectory = path;//导出默认路径
            fileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";//导出默认格式hhMMss
            fileDialog.FileName = "MES_TEMP_" + DateTime.Now.ToString("yyyyMMdd_HHmmss");
            //+"_"+ DateTime.Now.ToString();//导出默认名称
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                // gridControl1.Font = new Font("宋体", 10);
                //Lamex.Common.ExecelHelper.ExportToExcelHeader(gcViewMain, fileDialog.FileName);
                gcViewMain.ExportToXlsx(fileDialog.FileName);
                //DevExpress.XtraEditors.XtraMessageBox.Show("导出成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (DevExpress.XtraEditors.XtraMessageBox.Show("导出成功，是否打开文件？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    System.Diagnostics.Process.Start(fileDialog.FileName);//打开指定路径下的文件
            }


            base.DoExport(sender);
        }
        public override void DoReturn(IButtonInfo sender)
        {
            //plRight.Visible = false;
            base.DoReturn(sender);
        }
        private void gcView1_DoubleClick(object sender, EventArgs e)
        {

            if (gcViewMain.RowCount < 1)
            {
                if (Loginer.CurrentUser.ChangeLanguage == 0)
                    XtraMessageBox.Show("没有选中数据");
                else
                    XtraMessageBox.Show("No Choose Data");
                return;
            }
            if (IsFormEdit == 1)
            {
                plRight.Visible = true;
                plRight.AutoSize = false;
            }

            //if (!BuildSqlHelper.IsExistList(dtName)) return;

            //string strWhere = "";
            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    string[] subName = Loginer.CurrentUser.Email.Split('@');
            //    //string str = subName[0].Replace('.',' ').Trim().ToUpper();
            //    strWhere += " and UPPER( AUTHORITY_USER_NAME) like '%" + subName[0].ToUpper() + "%'";
            //    strWhere += " and DATABASE_NAME='LamexMESManager' ";
            //    strWhere += " and TABLE_NAME='" + dtName + "' ";
            //}

            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    if (!BuildSqlHelper.IsExistList(strWhere))
            //    {
            //        XtraMessageBox.Show("非授权用户，不允许修改数据！");
            //        return;
            //    }
            //}
            //else
            //{
            //    XtraMessageBox.Show("非授权用户，不允许修改数据！");
            //    return;
            //}
            int iRow = gcViewMain.FocusedRowHandle;
            if (iRow < 0) return;
            iCurrentRow = iRow;
            if (!BuildSqlHelper.IsExistList(dtName, dataBaseName))
            {

                RetureControlStr.SetControlValue(gcViewMain, plEditPanel, iRow, iType);

                return;
            }
            else
            {
                RetureControlStr.SetControlVaildValue(plEditPanel);
                RetureControlStr.SetControlValue(gcViewMain, plEditPanel, iRow, iType);
            }

            //RetureControlStr.SetControlVaildValue(gcmIWCEBox);
            //RetureControlStr.SetControlValue(gcViewMain, gcmIWCEBox, iRow);
            //IsEidtWhere = RetureControlStr.GetstrWhere(gcViewMain,dt,iRow);
            isEdit = "Edit";
            gcChangeLanguate();

        }
        private void gcView1_Click(object sender, EventArgs e)
        {
            if (gcViewMain.RowCount < 1)
            {
                //if (Loginer.CurrentUser.ChangeLanguage == 0)
                //    XtraMessageBox.Show("没有选中数据");
                //else
                //    XtraMessageBox.Show("No Choose Data");
                return;
            }
            int iRow = gcViewMain.FocusedRowHandle;
            if (iRow < 0) return;
            iCurrentRow = iRow;
            IsEidtWhere = RetureControlStr.GetstrWhere(gcViewMain, dt, iRow);
        }

        private void gcView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control & e.KeyCode == Keys.C)
            {
                Clipboard.SetDataObject(gcViewMain.GetFocusedRowCellValue(gcViewMain.FocusedColumn));
                e.Handled = true;
            }
        }

        private void gcViewMain_RowStyle(object sender, RowStyleEventArgs e)
        {

            //int hand = e.RowHandle;
            //if (hand < 0) return;
            //if (e.RowHandle==iCurrentRow)
            //    e.Appearance.BackColor = Color.Red;// 改变行背景颜色

        }
        private void uc_UcDoubleClick(object sender, EventArgs e)
        {
            ucPictrueEdit uc = sender as ucPictrueEdit;
            uc.LoadSelectPicture();
        }
        private void btn_Click(object sender, EventArgs e)
        {
            //string strWhere = "";
            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    string[] subName = Loginer.CurrentUser.Email.Split('@');
            //    //string str = subName[0].Replace('.',' ').Trim().ToUpper();
            //    strWhere += " and UPPER( AUTHORITY_USER_NAME) like '%" + subName[0].ToUpper() + "%'";
            //    strWhere += " and DATABASE_NAME='LamexMESManager' ";
            //    strWhere += " and TABLE_NAME='" + dtName + "' ";
            //}

            //if (!string.IsNullOrEmpty(Loginer.CurrentUser.Email))
            //{
            //    if (!BuildSqlHelper.IsExistList(strWhere))
            //    {
            //        XtraMessageBox.Show("非授权用户，操作未完成！");
            //        return;
            //    }
            //}
            //else
            //{
            //    XtraMessageBox.Show("非授权用户，操作未完成！");
            //    return;
            //}
            if (!BuildSqlHelper.IsExistList(dtName, dataBaseName)) return;

            foreach (Control c in gcmIWCEBox.Controls)
            {
                if (c is ucTextEdit)
                {
                    ucTextEdit ucEdit = c as ucTextEdit;
                    if (!string.IsNullOrEmpty(ucEdit.UcErrortip))
                        if (ucEdit.Alter()) return;

                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit ucEdit = c as ucComboBoxEdit;
                    if (!string.IsNullOrEmpty(ucEdit.UcErrortip))
                        if (ucEdit.Alter()) return;

                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit ucEdit = c as ucLookUpEdit;
                    if (!string.IsNullOrEmpty(ucEdit.UcErrortip))
                        if (ucEdit.Alter()) return;

                }
                else if (c is ucDateEdit)
                {
                    ucDateEdit ucEdit = c as ucDateEdit;
                    if (!string.IsNullOrEmpty(ucEdit.UcErrortip))
                        if (ucEdit.Alter()) return;

                }
                else if (c is ucMemoEdit)
                {
                    ucMemoEdit ucEdit = c as ucMemoEdit;
                    if (!string.IsNullOrEmpty(ucEdit.UcErrortip))
                        if (ucEdit.Alter()) return;

                }
                else if (c is ucCheckEdit)
                {
                    ucCheckEdit ucEdit = c as ucCheckEdit;
                    if (!string.IsNullOrEmpty(ucEdit.UcErrortip))
                        if (ucEdit.Alter()) return;

                }
                else if (c is ucDate)
                {
                    ucDate ucEdit = c as ucDate;
                    if (!string.IsNullOrEmpty(ucEdit.UcErrortip))
                        if (ucEdit.Alter()) return;

                }
                else if (c is ucPictrueEdit)
                {
                    ucPictrueEdit ucEdit = c as ucPictrueEdit;
                    if (!string.IsNullOrEmpty(ucEdit.UcErrortip))
                        if (ucEdit.Alter()) return;

                }
            }

            DataView dataView = dt.DefaultView;
            string keyStr = "";
            DataTable isCheckData = null;
            if ("LamexMESManager".ToLower()==dataBaseName.ToLower())
                isCheckData = BaseBuildSql.GetSysColunmNameList(dtName);
            else
                isCheckData = GetSysColunmNameList2(dtName,dataBaseName);
            foreach (DataRow dr in isCheckData.Rows)
            {
                if (dr["keyname"].ToString() == "key")
                    keyStr += dr["column_name"].ToString() + ",";
            }
            if (string.IsNullOrEmpty(keyStr))
            {
                XtraMessageBox.Show("不存在唯一ID,无法保存！");
                return;
            }

            
            //DataTable MainTable = dataView.ToTable(true, "FORM_TABLE_NAME");

            //string tableName = dt.Select("1=1").Distinct().FirstOrDefault()["FORM_TABLE_NAME"].ToString();
            if (iType == 0)
            {


                if (isEdit == "New")
                {
                    IsEidtWhere = RetureControlStr.GetstrEditWhereInsert(plEditPanel);
                    if (!string.IsNullOrEmpty(IsEidtWhere))
                    {
                        string strSql = "select * from  " + dataBaseName+".dbo."+dtName + " where 1=1 " + IsEidtWhere;
                        DataTable dtList = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
                        if (dtList.Rows.Count != 0)
                        {
                            XtraMessageBox.Show("数据已存在,无法保存！");
                            return;
                        }
                    }
                    if (BuildSqlHelper.Insert(plEditPanel, dtName,dataBaseName))
                    {
                        if (Loginer.CurrentUser.ChangeLanguage == 0)
                            XtraMessageBox.Show("新增数据成功!");
                        else
                            XtraMessageBox.Show("save successfully!");
                        RetureControlStr.SetControlVaildValue(plEditPanel);
                        DoView(null);
                        plRight.Visible = true;
                        //plRight.AutoSize = false;
                    }
                    else
                    {
                        if (Loginer.CurrentUser.ChangeLanguage == 0)
                            XtraMessageBox.Show("保存失败!");
                        else
                            XtraMessageBox.Show("save fail!");
                    }

                }
                else if (isEdit == "Edit")
                {
                    IsEidtWhere = RetureControlStr.GetstrEditWhere(plEditPanel, gcViewMain, iCurrentRow);
                    if (string.IsNullOrEmpty(IsEidtWhere))
                    {
                        if (Loginer.CurrentUser.ChangeLanguage == 0)
                            XtraMessageBox.Show("没有设置编辑条件");
                        else
                            XtraMessageBox.Show("No Setting Edit Filter !");
                        return;
                    }
                    if (BuildSqlHelper.Update(plEditPanel, dtName, IsEidtWhere, gcViewMain, iCurrentRow, dataBaseName))
                    {
                        if (Loginer.CurrentUser.ChangeLanguage == 0)
                            XtraMessageBox.Show("修改成功!");
                        else
                            XtraMessageBox.Show("Modify successfully!");
                        DoView(null);
                        RetureControlStr.SetControlReadOnlyValue(plEditPanel);

                        plRight.Visible = true;
                        //plRight.AutoSize = false;
                    }
                    else
                    {
                        if (Loginer.CurrentUser.ChangeLanguage == 0)
                            XtraMessageBox.Show("修改失败!");
                        else
                            XtraMessageBox.Show("Modify fail!");
                    }
                }
            }
            else if (iType == 1)
            {

                if (isEdit == "New")
                {
                    string strMaxWhere = RetureControlStr.GetstrEditWhereInsert2(plEditPanel, "true");
                    string strNowWhere = RetureControlStr.GetstrEditWhereInsert2(plEditPanel, "false");

                    if (!string.IsNullOrEmpty(strMaxWhere))
                    {
                        string strSql = "select * from  " +dataBaseName+".dbo."+ dtName + " where 1=1 " + strMaxWhere;
                        DataTable dtList = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
                        if (dtList.Rows.Count != 0)
                        {
                            strSql = "select * from  " + dataBaseName + ".dbo." + dtName + " where 1=1 " + strNowWhere;
                            DataTable dt2 = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
                            if (dt2.Rows.Count != 0)
                            {
                                if (string.IsNullOrEmpty(strNowWhere))
                                {
                                    if (Loginer.CurrentUser.ChangeLanguage == 0)
                                        XtraMessageBox.Show("没有设置编辑条件");
                                    else
                                        XtraMessageBox.Show("No Setting Edit Filter !");
                                    return;
                                }
                                if (BuildSqlHelper.Update(plEditPanel, dtName, strNowWhere, gcViewMain, iCurrentRow, dataBaseName))
                                {
                                    if (Loginer.CurrentUser.ChangeLanguage == 0)

                                        XtraMessageBox.Show("修改成功!");
                                    else
                                        XtraMessageBox.Show("Modify successfully!");
                                    RetureControlStr.SetControlReadOnlyValue(plEditPanel);
                                    DoView(null);
                                    plRight.Visible = true;
                                    //plRight.AutoSize = false;
                                }
                            }
                            else
                            {
                                if (BuildSqlHelper.Update3(plEditPanel, dtName, strMaxWhere, dataBaseName))
                                {
                                    if (BuildSqlHelper.Insert2(plEditPanel, dtName,dataBaseName))
                                    {
                                        if (Loginer.CurrentUser.ChangeLanguage == 0)
                                            XtraMessageBox.Show("新增数据成功!");
                                        else
                                            XtraMessageBox.Show("save successfully!");
                                        RetureControlStr.SetControlReadOnlyValue(plEditPanel);
                                        DoView(null);
                                        plRight.Visible = true;
                                        //plRight.AutoSize = false;
                                    }
                                }

                            }

                        }
                        else
                        {
                            if (BuildSqlHelper.Insert(plEditPanel, dtName,dataBaseName))
                            {
                                if (Loginer.CurrentUser.ChangeLanguage == 0)
                                    XtraMessageBox.Show("新增数据成功!");
                                else
                                    XtraMessageBox.Show("save successfully!");
                                DoView(null);
                                plRight.Visible = true;
                                //plRight.AutoSize = false;
                            }
                        }
                    }


                }
                else if (isEdit == "Edit")
                {
                    string strMaxWhere = RetureControlStr.GetstrEditWhere2(plEditPanel, "true", gcViewMain, iCurrentRow);
                    string strNowWhere = RetureControlStr.GetstrEditWhere2(plEditPanel, "false", gcViewMain, iCurrentRow);
                    if (!string.IsNullOrEmpty(IsEidtWhere))
                    {
                        if (!string.IsNullOrEmpty(strMaxWhere))
                        {
                            string strSql = "select * from  " + dataBaseName + ".dbo." + dtName + " where 1=1 " + strMaxWhere;
                            DataTable dtList = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
                            if (dtList.Rows.Count != 0)
                            {
                                strSql = "select * from  " + dataBaseName + ".dbo." + dtName + " where 1=1 " + strNowWhere;
                                DataTable dt2 = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
                                if (dt2.Rows.Count != 0)
                                {
                                    if (BuildSqlHelper.Update(plEditPanel, dtName, strNowWhere, gcViewMain, iCurrentRow, dataBaseName))
                                    {
                                        if (Loginer.CurrentUser.ChangeLanguage == 0)
                                            XtraMessageBox.Show("修改成功!");
                                        else
                                            XtraMessageBox.Show("Modify successfully!");
                                        RetureControlStr.SetControlReadOnlyValue(plEditPanel);
                                        DoView(null);
                                        plRight.Visible = true;
                                        //plRight.AutoSize = false;
                                    }
                                }
                                else
                                {
                                    if (BuildSqlHelper.Update2(plEditPanel, dtName, strNowWhere, gcViewMain, iCurrentRow, dataBaseName))
                                    {
                                        if (BuildSqlHelper.Insert2(plEditPanel, dtName, dataBaseName))
                                        {
                                            if (Loginer.CurrentUser.ChangeLanguage == 0)
                                                XtraMessageBox.Show("保存成功!");
                                            else
                                                XtraMessageBox.Show("save successfully!");
                                            RetureControlStr.SetControlReadOnlyValue(plEditPanel);
                                            DoView(null);
                                            plRight.Visible = true;
                                            //plRight.AutoSize = false;
                                        }
                                    }

                                }

                            }
                        }
                    }
                    else
                    {
                        if (Loginer.CurrentUser.ChangeLanguage == 0)
                            XtraMessageBox.Show("没有设置编辑条件");
                        else
                            XtraMessageBox.Show("No Setting Edit Filter !");
                        return;
                    }
                }



            }
        }

        public override void DoUpLoadSAP(IButtonInfo sender)
        {
            try
            {
                if (this.Text == "排产系数")
                {
                    FileImoprtHelper.ImportFormTypeList(gcViewMain, "排产系数");
                }
                else if (this.Text == "成本系数")
                {
                    FileImoprtHelper.ImportFormTypeList(gcViewMain, "成本系数");
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
            base.DoUpLoadSAP(sender);
        }

        public override void DoPrint(IButtonInfo sender)
        {
            ExecelHelper.GridViewToPrint(gcView1, this.Text);
            base.DoPrint(sender);
        }

        private DataTable GetSysColunmNameList2(string tableName,string dataName)
        {
            string sql = @"SELECT  
                        d.name as table_name,  
                        a.name column_name,
                        case when exists(SELECT 1 FROM {0}.dbo.sysobjects where xtype='PK' and name in (
                        SELECT name FROM {1}.dbo.sysindexes WHERE indid in(
                        SELECT indid FROM {2}.dbo.sysindexkeys WHERE id = a.id AND colid=a.colid 
                        ))) then 'key' else '' end as keyname, 
                        b.name column_type,
                        isnull(g.[value],'') column_remark
                        FROM {3}.dbo.syscolumns a 
                        left join {4}.dbo.systypes b on a.xtype=b.xusertype 
                        inner join {5}.dbo.sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties' 
                        left join {6}.dbo.syscomments e on a.cdefault=e.id 
                        left join sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id 
                        left join sys.extended_properties f on d.id=f.major_id and f.minor_id =0 
                        where d.name='MT_Resource_Worker_List' order by a.id,a.colorder ";
            sql = string.Format(sql,dataName, dataName, dataName, dataName, dataName, dataName, dataName);
            return  Lamex.Base.BaseBuildSql.GetDataTableBySql(sql);
            
        }
        public override void DoFeatureImport(IButtonInfo sender)
        {
            #region CSV导入
            SplashScreenTool.ShowSplashScreen(typeof(WaitForm1));
            //获取当前文件夹下所有的文件
            string path = @"\\Tx-fs10.lamex.com\tx-fs1\LAMEX\Parametric\FeatData\Aluminum";
            string pathBack = @"\\Tx-fs10.lamex.com\tx-fs1\LAMEX\NC\FeatData\Aluminum\";
            DirectoryInfo folder = new DirectoryInfo(path);
            int isums = 0, icount_true = 0, icount_false = 0;
            try
            {
                foreach (FileInfo file in folder.GetFiles("*.csv"))
                {
                    isums++;
                    //判断数据库是否存在，若存在则不允许保存
                    string sql = @" select [FILE_NAME] FROM [LamexMESManager].[dbo].[NC_PN_AL_FeatData_Creo]
                                    where [FILE_NAME]='" + file.Name + "'";
                    if (BaseBuildSql.GetDataTableBySql(sql).Rows.Count > 0)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("【" + file.Name + "】文件已存在，不允许重复获取！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        icount_false++;
                        continue;
                    }

                    DataTable TABLE_CREO = Lamex.Common.ExecelHelper.GetTable_FromCreo();
                    string fileName = file.FullName;
                    //采用流的方式读取
                    DataTable dataTable = Lamex.Common.ExecelHelper.CSVToDataTableByStreamReader(fileName);
                    if (dataTable.Rows.Count > 0)
                    {
                        for (int i = 0; i < dataTable.Rows.Count; i++)
                        {
                            DataRow dr = TABLE_CREO.NewRow();
                            dr["FILE_NAME"] = file.Name;
                            dr["DWG_NO"] = dataTable.Rows[i]["图纸编号"].ToString();
                            dr["MODULE_CODE"] = dataTable.Rows[i]["型材编号"].ToString();
                            dr["PART_NO"] = dataTable.Rows[i]["部件编号"].ToString();
                            dr["PART_LENGTH"] = dataTable.Rows[i]["长度"].ToString();
                            dr["WORK_SURFACE"] = dataTable.Rows[i]["加工面"].ToString();
                            dr["FACE_WIDTH"] = dataTable.Rows[i]["宽度"].ToString();
                            dr["FACE_HEIGHT"] = dataTable.Rows[i]["高度"].ToString();
                            dr["UDF_NAME"] = dataTable.Rows[i]["UDF名称"].ToString();
                            dr["FEATURE_TYPE"] = dataTable.Rows[i]["特征类型"].ToString();
                            dr["DEEP_CODE"] = dataTable.Rows[i]["深度代码"].ToString();
                            dr["COORD_X"] = dataTable.Rows[i]["X坐标"].ToString();
                            dr["COORD_Y"] = dataTable.Rows[i]["Y坐标"].ToString();
                            dr["COORD_Z"] = dataTable.Rows[i]["Z坐标"].ToString();
                            dr["FEATURE_DIA"] = dataTable.Rows[i]["直径"].ToString().ToUpper() == "NULL" ? null : dataTable.Rows[i]["直径"].ToString();
                            dr["SLOT_LENGTH"] = dataTable.Rows[i]["槽长"].ToString().ToUpper() == "NULL" ? null : dataTable.Rows[i]["槽长"].ToString();
                            dr["SLOT_WIDTH"] = dataTable.Rows[i]["槽宽"].ToString().ToUpper() == "NULL" ? null : dataTable.Rows[i]["槽宽"].ToString();
                            dr["FILLIT_RADIUS"] = dataTable.Rows[i]["圆角"].ToString().ToUpper() == "NULL" ? null : dataTable.Rows[i]["圆角"].ToString();
                            dr["FEATURE_DEPTH"] = dataTable.Rows[i]["深度"].ToString().ToUpper() == "NULL" ? null : dataTable.Rows[i]["深度"].ToString();
                            dr["CREO_OUTPUT_TIME"] = file.CreationTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
                            dr["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                            dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.Account;
                            TABLE_CREO.Rows.Add(dr);
                        }
                    }
                    //批量插入数据库
                    if (BaseBuildSql.ExcuteInsert(TABLE_CREO, "NC_PN_AL_FeatData_Creo"))
                    {
                        TABLE_CREO = new DataTable();
                        // 导入成功后移动文件到新的文件夹
                        File.Copy(fileName, pathBack + file.Name, true);
                        File.Delete(fileName);
                        icount_true++;
                    }
                    else
                    {
                        icount_false++;
                    }

                }
                DevExpress.XtraEditors.XtraMessageBox.Show("共【" + isums + "】个文件，成功【" + icount_true + "】个，失败【" + icount_false + "】个！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                SplashScreenTool.CloseSplashScreen();
            }
            catch (Exception ex)
            {
                SplashScreenTool.CloseSplashScreen();
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message);
            }
            #endregion
            base.DoFeatureImport(sender);
        }

    }   
}
